<template>
	<view>
		<!-- #ifdef MP-WEIXIN -->
		<view class="ad_wrap">
			<common-ad unitId="adunit-71932bc12f49fc91" adType="custom" />
		</view>
		<!-- #endif -->
		<view class="cu-card article express-item" @click="gotoExpressing" v-for="(priceItem, index) in expressPriceList" :key="priceItem.companyCode">
			<view class="cu-item shadow-wrap" :class="index === expressPriceList.length - 1 ? '' : 'solid-bottom'">
				<view class="title"><view class="text-cut">{{priceItem.companyName}}</view></view>
				<view class="content">
					<div class="express-logo-wrap">
						<image class="express-logo" :src="`../../static/express-icon/${priceItem.companyCode}.png`"
						 mode="aspectFill"></image>
					</div>
					<view class="desc desc-wrap">
						<view class="price-item">首重价格：{{priceItem.firstPrice}}元/KG</view>
						<view class="price-item">续重：{{priceItem.overprice}}元/KG</view>
						<view class="price-item">价格：{{priceItem.totalPrice}}</view>
						<view v-if="cheapIndex.indexOf(index) !== -1">
							<view class="cu-tag bg-green light sm round">便宜</view>
						</view>
						<view class="goto-mail-link text-gray">
							<text>去邮寄</text>
							<text class="cuIcon-right"></text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- #ifdef MP-WEIXIN -->
		<view class="ad_wrap" v-if="expressPriceList && expressPriceList.length > 5">
			<common-ad unitId="adunit-ecf87a78f9a21ddf" adType="video" />
		</view>
		<!-- #endif -->
	</view>
</template>

<script>
	import { mapActions, mapState } from 'vuex';
	
	export default {
		data() {
			return {
				
			}
		},
		computed: {
			...mapState(['expressPriceList','expressAllList']),
			cheapIndex(){
				let indexs = [];
				if (!this.expressPriceList || this.expressPriceList.length == 0) {
					return indexs;
				}
				let minPrice = this.expressPriceList[0].totalPrice;
				this.expressPriceList.forEach((express, index) => {
					if (express.totalPrice < minPrice || express.totalPrice === minPrice) {
						indexs.push(index)
					}
				})
				return indexs;
			}
		},
		methods: {
			...mapActions(['getExpressList']),
			gotoExpressing() {
				uni.switchTab({
					url: '/pages/expressList/expressList'
				})
			}
		}
	}
</script>

<style>
.express-logo-wrap{
	padding: 30rpx;
}
.express-logo{
	width: 56px;
	height: 56px;
}
.desc-wrap{
	position: relative;
}
.goto-mail-link{
	position: absolute;
	right: 10px;
	top: 50%;
	transform: translateY(-50%);
}
.express-item .cu-item{
	margin: 15rpx;
}
</style>
